// 配置代理 - 用于联调
const { createProxyMiddleware } = require('http-proxy-middleware')
console.log('PROXY: ', process.env.PROXY_ENV_API)

module.exports = function (app) {
  if (process.env.PROXY_ENV === 'proxy') {
    app.use(
      createProxyMiddleware('/api/xp', {
        target: process.env.PROXY_ENV_XP,
        changeOrigin: true,
        pathRewrite: { '^/api/xp': '/' },
      }),
      createProxyMiddleware('/api', {
        target: process.env.PROXY_ENV_API,
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/'
        }
      })
    )
  }
}
